/*Copyright (C) 2013-2021 LZE*/
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 100010;
int n,a[N],d[N],cnt = 0,maxn=0;
int main(){
	scanf("%d",&n);
	for(int i = 1;i <= n;i++){
		scanf("%d",&a[i]);
	}
	for(int i = 1;i <= n;i++){
		if(d[cnt] <= a[i]){
			++cnt;
			d[cnt] = a[i];
		}else{
			d[upper_bound(d+1,d+1+cnt,a[i])-d]=a[i];
		}
	}
	printf("%d\n",cnt);
	return 0;
}